package org.dreamwork.jasmine2.sample.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-6-29
 * Time: 下午12:00
 */
public class ResourceServlet extends HttpServlet {
    @Override
    protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType ("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter ();
        writer.println ("request uri = " + request.getRequestURI () + "<br/>");
        writer.println ("servlet path = " + request.getServletPath () + "<br/>");
        writer.println ("request url = " + request.getRequestURL () + "<br/>");
        writer.println ("path info = " + request.getPathInfo () + "<br/>");

        String uri = request.getRequestURI ();
        String path = request.getServletPath ();
        int pos = uri.indexOf (path);
        String resourceName = uri.substring (pos + path.length ());
        writer.println ("resource = " + resourceName + "<br/>");
    }
}